<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/vue.min.js"></script>
</head>
<body>
    <div id="app">
        <com1 :parames = "msg" @func = "getMsgForSon"></com1>
    </div>
     
    <template id="tmpl">
        <div>
            <h1>这是子元素 --- {{ parames }}</h1>
            <input type="button" value="向父组件传递消息" @click = "sendMsg">
        </div>
    </template>
    <script>
        var com1 = {
            template: '#tmpl',
            data() {
                return {
                    msg: '做一个孝顺的孩子，孝顺父母!',
                    msgFormSon: ''
                }
            },
            //定义拿到父组件data中的数据
            props: ['parames'],
            methods: {
                sendMsg() {
                    this.$emit("func", this.msg)
                }
            },
        }

        var vm = new Vue({
            el:"#app",
            data:{
                msg:'爸爸有钱，儿子要吗？'
            },
            methods: {
                //拿到子组件中data中的数据
                getMsgForSon(data) {
                    this.msgFormSon = data
                    console.log(this.msgFormSon)
                }
            },
            components: {
                com1
            }
        })
    </script>
</body>
</html>